package infrastructure;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import common.messages.KVMessage;
import common.messages.KVMessage.MessageType;

@XmlRootElement
public class KVMessageImp implements KVMessage {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String value;
	private String key;
	private StatusType status;
	private MessageType type;
	private String from;
	private String to;
	
	public KVMessageImp(){		
	}
	
	public KVMessageImp(MessageType type, String value, String key, StatusType status) {
		this.type = type;
		this.value = value;
		this.key = key;
		this.status = status;
	}
	
	public KVMessageImp(MessageType type, StatusType status){
		this.type = type;
		this.status = status;
	}
	
	public KVMessageImp(MessageType type, String value) {
		this.type = type;
		this.value = value;
	}

	@Override
	public String getKey() {		
		return this.key;
	}
	
	@XmlElement
	public void setKey(String key) {		
		this.key = key;
	}

	@Override
	public String getValue() {
		return this.value;
	}
	
	@XmlElement
	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public StatusType getStatus() {
		return status;
	}

	@XmlElement
	public void setStatus(StatusType status) {
		this.status = status;
	}
	
	@Override
	public String toString() {
		String message = "KVMessage ";
		if (this.status != null)
			message += " | status: " + this.status;
		if (this.key != null)
			message += " | key " + this.key;
		if (this.value != null)
			message += " | value " + this.value;		
		if (this.type != null)
			message += " | type " + this.type;
		
		return message;
	}

	@Override
	public MessageType getMessageType() {
		return type;
	}
	
	@XmlElement
	public void setMessageType(MessageType type){
		this.type = type;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

	public String getTo() {
		return to;
	}

	public void setTo(String to) {
		this.to = to;
	}
}
